<template>
  <div>
    <el-dropdown>
      <el-icon><MoreFilled /></el-icon><arrow-down />
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item
            :icon="WarnTriangleFilled"
            v-if="myId != propsId.badUserId"
            @click="reportOther1"
          >
            举报
          </el-dropdown-item>
          <el-dropdown-item :icon="Delete" v-else @click="deletePinlun"
            >删除</el-dropdown-item
          >
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>
<script setup>
import { Delete, WarnTriangleFilled, MoreFilled } from '@element-plus/icons-vue'
import { ref, defineProps } from 'vue'
import axios from 'axios'
const propsId = defineProps([
  'badUserId',
  'pinId',
  'badUserName',
  'Content',
  'sonCommentId'
])
console.log(propsId.badUserId)
const myId = ref(localStorage.getItem('userSelfId'))
function reportOther1() {
  axios({
    url: 'http://localhost:8080/examine/report',
    method: 'post',
    contentType: 'application/json',
    headers: {
      token: localStorage.getItem('token')
    },
    data: {
      reviewId: propsId.pinId,
      baduUerId: propsId.badUserId,
      badUser: propsId.badUserName,
      content: propsId.Content
    }
  }).then(function (res) {
    alert(JSON.stringify(res.data))
  })
}

function deletePinlun() {
  if (propsId.pinId) {
    axios({
      url: 'http://localhost:8080/comment/delete',
      method: 'delete',
      contentType: 'application/json',
      headers: {
        token: localStorage.getItem('token')
      },
      data: {
        rootCommentId: propsId.pinId
      }
    }).then(function (res) {
      alert(JSON.stringify(res.data))
    })
  } else {
    axios({
      url: 'http://localhost:8080/Comment/son/delete',
      method: 'delete',
      contentType: 'application/json',
      headers: {
        token: localStorage.getItem('token')
      },
      data: {
        sonCommentId: propsId.sonCommentId
      }
    }).then(function (res) {
      alert(JSON.stringify(res.data))
    })
  }
}
</script>
